package com.pro.controller;

import com.pro.pojo.JsMicrocircle;
import com.pro.pojo.JsonData;
import com.pro.service.JsMicrocircleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:JsMicrocircleController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2022/1/7 11:37
 * @Author: ZPT
 */
@RestController
@RequestMapping("/microcircle")
public class JsMicrocircleController {
    @Autowired
    private JsMicrocircleService jsMicrocircleService;

    /**
     * @author ZPT
     * @date 2022/2/8 14:56
     * @content :查询微圈数据
     */
    @RequestMapping("/getMicrocircleTable")
    public JsonData getMicrocircleTable(Integer acticleCategroyId, Integer page, Integer limit, String artcleTitle, String nickname, String account) {
        List<JsMicrocircle> microcircleTable = jsMicrocircleService.getMicrocircleTable(acticleCategroyId,page, limit,artcleTitle,nickname,account);
        //查看数量
        Integer count = jsMicrocircleService.getCount(acticleCategroyId, artcleTitle, nickname, account);
        return microcircleTable != null ? JsonData.buildSuccess(microcircleTable,count) : JsonData.buildError("服务端错误");
    }

    /**
     * @author ZPT
     * @date 2022/1/8 11:53
     * @content :微圈的删除
     */
    @RequestMapping("/deleteMicrocircle")
    public JsonData deleteMicrocircle(Integer microcircleId, Integer userId) {
        Boolean aBoolean = jsMicrocircleService.deleteMicrocircle(microcircleId, userId);
        return aBoolean != null ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("服务端错误");
    }

    /**
     * @author ZPT
     * @date 2022/1/8 12:22
     * @content :根据id查询微圈数据
     */
    @RequestMapping("/getMicrocircleById")
    public JsonData getMicrocircleById(Integer microcircleId, Integer userId) {
        JsMicrocircle microcircle = jsMicrocircleService.getMicrocircleById(microcircleId, userId);
        return microcircle != null ? JsonData.buildSuccess(microcircle) : JsonData.buildError("服务端错误");
    }


}
